package jp.co.ricoh.melody.views.customviews;

import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import jp.co.ricoh.melody.R;
import jp.co.ricoh.melody.utils.CommonUtils;
import jp.co.ricoh.melody.utils.ConstantUtils;

/**
 * Copyright (C) 2016 RICOH Co.,LTD.
 * All rights reserved.
 * <p/>
 * Horizontal day list of week view
 */
public class DayListView extends LinearLayout {

    private List<TextView> mItemViews = new ArrayList<>();

    public DayListView(Context context) {
        super(context);
        init();
    }

    public DayListView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public DayListView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        inflate(getContext(), R.layout.layout_day_list, this);
        for (int i = 0; i < ConstantUtils.DAY_OF_WEEK; ++i) {
            mItemViews.add((TextView) ((ViewGroup) getChildAt(0)).getChildAt(i));
            mItemViews.get(i).setText(CommonUtils.getReadableDay(i));
        }


    }

    /**
     * Set days, true if day enabled
     *
     * @param days
     */
    public void setDays(boolean[] days) {
        if (days == null || days.length != ConstantUtils.DAY_OF_WEEK) {
            throw new IllegalArgumentException("Invalid days of week");
        }

        for (int i = 0; i < days.length; ++i) {
            mItemViews.get(i).setVisibility(days[i] ? VISIBLE : GONE);
        }
    }

}
